package com.coderman.infosys.auth.adapter.controller.user;

import com.coderman.infosys.auth.adapter.controller.BaseController;
import com.coderman.infosys.auth.adapter.convert.UserGroupConverter;
import com.coderman.infosys.auth.domain.bo.user.UserGroupBO;
import com.coderman.infosys.auth.domain.enums.errors.UserGroupErrorEnum;
import com.coderman.infosys.auth.domain.repository.UserRoleRepository;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.coderman.infosys.auth.adapter.vo.user.request.CreateUserGroupRequestVO;
import com.coderman.infosys.auth.adapter.vo.user.UserGroupVO;
import com.coderman.infosys.auth.adapter.vo.user.request.UpdateUserGroupRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;


/**
* @Description:控制层
* @Author:
* @CreateTime:2022-01-04 15:27:39
* @version v1.0
*/
@RestController
public class UserGroupController extends BaseController {
	
	protected Logger logger = LoggerFactory.getLogger(UserGroupController.class);

	@Autowired
	private UserRoleRepository userRoleRepository;

	/**
	 *
	 * @Description 创建用户组
	 * @param createUserGroupRequestVO
	 * @return UserGroupVO
	 */
	@RequestMapping(value = "/usergroup/create")
	public ResultDataDto<Boolean> createUserGroup(@RequestBody CreateUserGroupRequestVO createUserGroupRequestVO){
		UserGroupBO userGroupBO = UserGroupConverter.INSTANCE.vo2bo(createUserGroupRequestVO);
		userRoleRepository.registUserGroup(userGroupBO);
		return ResultDataDto.success(true);
	}

	/**
	 *
	 * @Description 修改用户组信息
	 * @param updateUserGroupRequestVO
	 * @return Boolean
	 */
	@RequestMapping(value = "/usergroup/upate")
	public ResultDataDto<Boolean> updateUserGroup(@RequestBody UpdateUserGroupRequestVO updateUserGroupRequestVO){
		UserGroupBO userGroupBO = UserGroupConverter.INSTANCE.vo2bo(updateUserGroupRequestVO);
		userRoleRepository.updateUserGroup(userGroupBO);
		return ResultDataDto.success(true);
	}

	/**
	 * 这个API设计的不够好
	 * @Description 设置用户组状态
	 * @param groupCode
	 * @param status
	 * @return Boolean
	 */
	@RequestMapping(value = "/usergroup/changestatus")
	public ResultDataDto<Boolean> updateUserGroupStatus(@RequestBody String groupCode, @RequestBody Integer status){
		return null;
	}

	/**
	 *
	 * @Description 禁用用户组
	 * @param groupCode
	 * @return Boolean
	 */
	@RequestMapping(value = "/usergroup/disable")
	public ResultDataDto<Boolean> disableUserGroup(@RequestBody String groupCode){
		Boolean success = userRoleRepository.disableUserGroup(groupCode);
		if(success){
			return ResultDataDto.success(true);
		}
		return ResultDataDto.fail(UserGroupErrorEnum.USER_GROUP_DISABLE_ERROR);
	}

	/**
	 *
	 * @Description 启用用户组
	 * @param groupCode
	 * @return Boolean
	 */
	@RequestMapping(value = "/usergroup/enable")
	public ResultDataDto<Boolean> enableUserGroup(@RequestBody String groupCode){
		Boolean success = userRoleRepository.enableUserGroup(groupCode);
		if(success){
			return ResultDataDto.success(true);
		}
		return ResultDataDto.fail(UserGroupErrorEnum.USER_GROUP_ENABLE_ERROR);

	}


}


